package com.burgstaller.aGTD;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.burgstaller.aGTD.utils.AbstractListBase;
import com.burgstaller.aGTD.utils.IconedCursorAdapter;
import com.burgstaller.aGTD.utils.IconedTaskCursorAdapter;
import com.burgstaller.controls.IconifiedTextView;
import com.burgstaller.provider.AGtd;

public class ContextList extends AbstractListBase {
	/**
	 * The columns we are interested in from the database
	 */
	private static final String[] PROJECTION = new String[] {
			AGtd.Contexts._ID, AGtd.Contexts.TITLE };
	private static Drawable s_normalIcon;
	
	@Override
	public void onCreate(Bundle icicle) {
		if (s_normalIcon == null) {
			s_normalIcon = getResources().getDrawable(R.drawable.context);
		}
		super.onCreate(icicle);
	}
	
	@Override
	protected Uri getListItemBaseURI() {
		return AGtd.Tasks.CONTENT_URI_FOR_CONTEXT;
	}

	@Override
	protected String[] getProjection() {
		return PROJECTION;
	}

	@Override
	protected String getClickAction() {
		return Intent.VIEW_ACTION;
	}
	
	@Override
	protected String getTargetViewTitle(View v) {
		return String.format(getString(R.string.header_tasks_for_context), 
				((IconifiedTextView) v).getText());
	}
	
	@Override
	protected ListAdapter provideListAdapter() {
		return new IconedCursorAdapter(m_cursor, this, 1,
				s_normalIcon);
	}
}